﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Windows.Forms;
using Telerik.WinControls.UI;

namespace POS.UI.Mantenimientos
{
    public partial class MantArticulosForm : MantForm
    {
        #region Constructors

        public MantArticulosForm()
        {
            InitializeComponent();
        }

        #endregion

        #region Declarations

        private const int PreciosGridColLista = 0;
        private const int PreciosGridColCosto = 1;
        private const int PreciosGridColMargen = 2;
        private const int PreciosGridColPrecio = 3;
        private const int PreciosGridColImpuesto = 4;
        private const int PreciosGridColPrecioImp = 5;
        
        //private bool changingPrice;

        //private BindingSource availableContactsBindingSource = new BindingSource();
        //private List<BEContacto> availableContacts = new List<BEContacto>();
        
        #endregion

        #region Event Handlers
        
        private void addProveedorButton_Click(object sender, EventArgs e)
        {
            MoveSelectedListBoxItems(availableProveedorListBox, selectedProveedorListBox);
        }

        private void removeProveedorButton_Click(object sender, EventArgs e)
        {
            MoveSelectedListBoxItems(selectedProveedorListBox, availableProveedorListBox);
        }
        
        #endregion

        #region Methods: Non-Public

        protected override bool ValidateInput()
        {
            return true;
        }

        protected override void Save()
        {
            throw new NotImplementedException();
        }

        protected override void Delete()
        {
            throw new NotImplementedException();
        }
        
        private static void MoveSelectedListBoxItems(ListBox source, ListBox target)
        {
            var toDelete = new List<object>();
            foreach (var item in source.SelectedItems)
            {
                toDelete.Add(item);
                target.Items.Add(item);
            }

            foreach (var item in toDelete)
                source.Items.Remove(item);
        }
        
        #endregion

        private void MantArticulosForm_Load(object sender, EventArgs e)
        {
            ConfigureGrid();
        }

        private void ConfigureGrid()
        {
            for (var i = 0; i < 10; i++)
            {
                radGridView1.Rows.AddNew();
                radGridView1.Rows[i].Cells[PreciosGridColLista].Value = i+1;
            }

            foreach (var col in radGridView1.Columns)
                if (col.DataType == typeof(decimal))
                    col.FormatString = "{0:#,###0.00}";
        }
    }
}